<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../../start/layui/css/layui.css" media="all">
    <style>
        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }
    </style>
    <script src="../../../../start/layui/layui.js"></script>
</head>
<body>
<form method="post" class="layui-form">
    <div  class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">应收费用</label>
            <div class="layui-input-inline">
                <input type="tel" id="aggregateAmount" readonly="readonly"  autocomplete="on" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">实收金额</label>
            <div class="layui-input-inline">
                <input type="tel" id="nowClosed"   autocomplete="on" class="layui-input">
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">欠收金额</label>
            <div class="layui-input-inline">
                <input type="tel" id="freightCollect"   autocomplete="on" class="layui-input">
            </div>
        </div>
    </div>
    <div  class="layui-row" style="margin-top: 10px">
        <div class="layui-col-md4">
            <label class="layui-form-label">付款方式</label>
            <div class="layui-input-inline">
                <select id="paymentmethod">
                    <option value="">请选择</option>
                    <option value="现金">现金</option>
                    <option value="微信">微信</option>
                    <option value="支付宝">支付宝</option>
                    <option value="刷卡">刷卡</option>
                </select>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-inline">
                <textarea id="remark" placeholder="请输入内容" readonly="readonly" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-col-md4">
            <label class="layui-form-label">&nbsp;</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </div>
</form>
</body>
</html>
<script>
    layui.use(['form','jquery','table'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;

        //显示网址
        var locationi=location.href;
        //根据下标截取字符串获得id
        var id=locationi.substring(locationi.indexOf("=")+1);
        setTimeout(function () {
            $.ajax({
                url: "../../../../FinancingControllerGetFreightinformationTableByWaybill_id",
                type: "post",
                data: {
                    waybill_id:id
                },
                dataType: "json",
                success: function (data) {
                    //应收
                    $("#aggregateAmount").val(data.receivables-data.realizeFee)
                    if (data.receivables-data.realizeFee==0.00){
                        $("#nowClosed").val(0.00);
                        $("#freightCollect").val(0.00);
                    }
                    //备注
                    $("#remark").val(data.remark)
                    $("#paymentmethod option[value='"+data.paymentMethod+"']").attr("selected","selected");
                    //刷新
                    form.render("select");
                }
            })
         }, 400);


        $("#nowClosed").blur(function () {
            if ($("#nowClosed").val()==null || $("#nowClosed").val()==""){
                alert("不能为空")
                $("#nowClosed").val(0);
                $("#freightCollect").val($("#aggregateAmount").val());
            } else if ($("#aggregateAmount").val()<$("#nowClosed").val()){
                alert("实收金额不能大于应收金额")
                $("#nowClosed").val(0);
                $("#freightCollect").val($("#aggregateAmount").val());
            } else {
                $("#freightCollect").val($("#aggregateAmount").val()-$("#nowClosed").val());
            }
        })



        //修改状态
        form.on('submit(demo1)', function(data){
            if ($("#aggregateAmount").val()<$("#nowClosed").val()){
                alert("实收金额不能大于应收金额")
                return false;
            } else {
                $.ajax({
                    url: "../../../../FinancingControllerUpdateVerification",
                    type: "post",
                    data:{
                        waybill_id:id,
                        receivables: $("#aggregateAmount").val(),
                        realizefee: $("#nowClosed").val(),
                        owefee:$("#aggregateAmount").val()-$("#nowClosed").val()
                    },
                    dataType: "text",
                    success: function (data) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        layer.closeAll("iframe");//关闭iframe层
                        //修改成功后刷新父界面
                        window.parent.location.reload();
                    }
                })
                return false;
            }
        });
    })
</script>